from flask import Flask, request, url_for,render_template,redirect
from werkzeug.utils import secure_filename
app = Flask(__name__)

'''
	一.form表单中的参数 可以用  request.form['参数']获取到值
	二。url中参数，比如 ?id = 123 可以使用args属性 如；request.args.get('id')获取到
	三。 url_for()参数为方法的名称，可以获取到路由的名称
	

'''


@app.route('/')
def hello_world():
    return 'Hello, World!123'

@app.route('/user')
def user_list():
	return 'i am users'

@app.route('/page/<num>')
def pagelist(num = 1):
	id = request.args.get('id')
	return num + id

@app.route('/post/<post_id>')
def postlist(post_id):
	return post_id

@app.route('/path/<path:subpath>')
def path_list(subpath):
	return subpath
@app.route('/login', methods=['GET', 'POST'])
def loign():
	error = None
	if request.method == 'POST':
		if request.form['username'] == '111111':
			return redirect(url_for('compony')) #内部路由的跳转
	return render_template('login.html', error = error)
@app.route('/compony')
def compony():
	return render_template('compony.html')

@app.route('/upload', methods = ['GET', 'POST'])     # 上传图片
def upload():
	if request.method == 'POST':
		f = request.files['the_file']
		f.save(secure_filename(f.filename))
	return render_template('upload.html')


@app.errorhandler(404)             # 404页面统一跳这个页面
def page_not_found(error):
    return render_template('page_not_found.html'), 404











	